package com.gruppsex.trainingdairy;

import java.util.ArrayList;
import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.ListView;

public class CalenderActivity extends Activity {
	ArrayList<String> arrayList = new ArrayList<String>();
	ArrayList<String> lister = new ArrayList<String>();

	private ListView listView;
	private ArrayAdapter<String> adapter;
	private Calendar calendar;
	private DatePicker datePicker;
	private int day;
	private int month;
	private int year;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		overridePendingTransition(R.anim.fadein, R.anim.fadeout);
		setContentView(R.layout.calender);
		datePicker = (DatePicker) findViewById(R.id.datePicker1);
	}

	public void listView(ArrayList<String> date) {
		arrayList.clear();
		arrayList = date;
		listView = (ListView) findViewById(R.id.listViewActivityHistory);
		adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, arrayList);
		listView.setAdapter(adapter);
	}

	public String getDateFromDatePicket(DatePicker datePicker) {
		day = datePicker.getDayOfMonth();
		month = datePicker.getMonth();
		year = datePicker.getYear();
		calendar = Calendar.getInstance();
		calendar.set(year, month, day);
		day = calendar.get(calendar.DATE);
		month = calendar.get(calendar.MONTH);
		year = calendar.get(calendar.YEAR);
		String s = "" + day + "-" + (month + 1) + "-" + year;
		return s;
	}

	public void onBtnClicked(View v) {
		switch (v.getId()) {
		case R.id.buttonShowEvents:
			try {
				DataBaseHelper dbHelper = new DataBaseHelper(this);
				dbHelper.openDataBase();
				ArrayList<String> dayPass = dbHelper
						.getDayPassAtDate(getDateFromDatePicket(datePicker));
				listView(dayPass);
				dbHelper.close();
			} catch (Exception e) {
			}
			break;
		}
	}
}
